package com.ruoyi.game.service;

import java.io.IOException;
import java.util.List;

import com.ruoyi.game.controller.dto.CheckOpReq;
import com.ruoyi.game.controller.dto.CheckOpResp;
import com.ruoyi.game.core.GameRoomCore;
import com.ruoyi.game.domain.GameRoom;
import com.ruoyi.game.websocket.message.packet.*;
import com.ruoyi.game.websocket.message.testpacket.DealReq;
import org.springframework.web.socket.WebSocketSession;

/**
 * 房间Service接口
 * 
 * @author ruoyi
 * @date 2025-04-18
 */
public interface IGameRoomService 
{
    /**
     * 查询房间
     * 
     * @param id 房间主键
     * @return 房间
     */
    public GameRoom selectGameRoomById(Long id);

    /**
     * 查询房间列表
     * 
     * @param gameRoom 房间
     * @return 房间集合
     */
    public List<GameRoom> selectGameRoomList(GameRoom gameRoom);

    /**
     * 新增房间
     * 
     * @param gameRoom 房间
     * @return 结果
     */
    public int insertGameRoom(GameRoom gameRoom);

    /**
     * 修改房间
     * 
     * @param gameRoom 房间
     * @return 结果
     */
    public int updateGameRoom(GameRoom gameRoom);

    /**
     * 批量删除房间
     * 
     * @param ids 需要删除的房间主键集合
     * @return 结果
     */
    public int deleteGameRoomByIds(Long[] ids);

    /**
     * 删除房间信息
     * 
     * @param id 房间主键
     * @return 结果
     */
    public int deleteGameRoomById(Long id);

    /**
     * 预判出牌
     * @param req 检查出牌封包
     * @return
     */
    public CheckOpResp checkCardOp(CheckOpReq req, Long playerId);

    public GameRoomCore createRoom(Long dbId, String roomKey, boolean robotRoom);
    public GameRoomCore getRoom(Long roomId);
    public void removeRoom(Long roomId);

    public boolean existsByRoomCode(String roomCode);
    public GameRoom selectByRoomCode(String roomCode);
    public GameRoomCore requireRoomByPlayerId(Long playerId);
    public int deleteExpiredWaitingRooms();
    /**
     * 根据房间号查询房间
     */
    public GameRoom selectGameRoomByCode(String roomCode);

    /* ------------------------------------------------------------ */
    /*                WebSocket 入口（由 GameWsDispatcher 调用）     */
    /* ------------------------------------------------------------ */
    public void join(WebSocketSession session, JoinRoomReq req);
    public void ready(WebSocketSession session, ReadyReq req);
    public void trusteeship(WebSocketSession session, TrusteeshipReq req);
    public void chat(WebSocketSession session, ChatReq req);
    public void outPlayerCard(WebSocketSession session, OutCardReq req) throws IOException;
    public void leave(WebSocketSession session, LeaveRoomReq req);
    public void dissolve(WebSocketSession session, DissolveRoomReq req);



    /* ------------------------------------------------------------ */
    /*                WebSocket Test 入口（由 GameWsDispatcher 调用） */
    /* ------------------------------------------------------------ */
    public void mockShuffleAndDeal(WebSocketSession session, DealReq req);

}
